#include <bits/stdc++.h>

const int MAXN = 200005;

using namespace std;

int N, M, T;

struct Edge {
	int u, v;
	unsigned long long w;
	bool p = 0;
} E[MAXN];

struct Node {
	int v, id;
};

int f[MAXN];

inline int F (const int x) {
	return x == f[x] ? x : f[x] = F (f[x]);
}

unsigned long long V[MAXN];
vector <Node> G[MAXN];

inline void Kruskal () {
	for (int i = 1; i <= N; ++ i) f[i] = i;
	int Cnt = 1, u, v;
	
	for (int i = 1; i <= M; ++ i) {
		u = E[i].u, v = E[i].v;
		u = F (u), v = F (v);
		if (u == v) continue ;
		f[u] = v, E[i].p = 1 ;
		G[E[i].u].push_back ({E[i].v, i});
		G[E[i].v].push_back ({E[i].u, i});
		if (++ Cnt == N) break ;
	}
}

inline unsigned long long DFS (const int x, const int f, const int id) {
	unsigned long long Ret = 0;
	for (auto i : G[x])
		if (i.v != f)
			Ret ^= DFS (i.v, x, i.id);
	Ret ^= V[x];
//	cerr << id << ' ' << Ret << '\n';
	E[id].w = Ret;
	return Ret;
}


namespace Basis {
	unsigned long long B[64];
	bool Q = 0;
	
	inline void Clr () {
		Q = 0;
		for (int i = 1; i < 64; ++ i) B[i] = 0;
	}
	
	inline void Ins (unsigned long long x) {
		for (int i = 63; ~ i; -- i)
			if ((x >> i) & 1) {
				if (B[i]) x ^= B[i];
				else return B[i] = x, void ();
			}
		Q = 1;
	}
	
	inline bool Chk () {
		return Q;
	}
}

int K, D;

mt19937_64 r_64 (time (0));

int main () {
	
	freopen ("graph.in", "r", stdin);
	freopen ("graph.out", "w", stdout);
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	
	cin >> N >> M;
	
	for (int i = 1; i <= M; ++ i) cin >> E[i].u >> E[i].v;
	
	Kruskal ();
	
	for (int i = 1; i <= M; ++ i)
		if (!E[i].p) E[i].w = r_64 (), V[E[i].u] ^= E[i].w, V[E[i].v] ^= E[i].w;
		
//	for (int i = 1; i <= N; ++ i) cerr << i << " PointVal : " << V[i] << '\n';
	
	DFS (1, 0, 0);
	
//	for (int i = 1; i <= M; ++ i)
//		cerr << "From : " << E[i].u << " To : " << E[i].v << " onTree : " << E[i].p << " Val : " << E[i].w << '\n';
	
	cin >> T;
	
	for (int i = 1; i <= T; ++ i) {
		cin >> K, Basis::Clr ();
		for (int j = 1; j <= K; ++ j)
			cin >> D, Basis::Ins (E[D].w);
		cout << (Basis::Chk () ? "NO" : "YES") << '\n';
	}
	
	return 0;
}